<template>
    <div v-if="detailsVisible">
        <el-collapse v-model="activeNames"  accordion>
            <el-collapse-item  name="1">
                <template slot="title">{{typeB}} 历次记录<i class="header-icon el-icon-info" style="margin-left: 10px;"></i></template>
                <lcjl ref="lcjl" v-on:serchrecorde="serchrecorde" v-on:serchfile="dbFilerecode"></lcjl>
            </el-collapse-item>
            <el-collapse-item  name="2" class="huanjiexuanju_file" v-show="disabledTwo"> 
                <template slot="title">
                  {{typeB}} 相关文件
                    <Badge dot v-if="hasnewfile==true">
                        <Icon type="ios-albums"  style="margin-left: 10px;"></Icon>
                    </Badge>
                    <Icon type="ios-albums"  style="margin-left: 10px;" v-if="hasnewfile==false"></Icon>
                </template>
                <showfiles ref="showfiles"></showfiles>
            </el-collapse-item>
            <el-collapse-item  name="3" class="huanjiexuanju_file" v-show="disabledTwo"> 
                <template slot="title">
                  {{typeB}} {{year}}年度结果
                    <Badge dot v-if="hasnewfile==true">
                        <Icon type="ios-albums"  style="margin-left: 10px;"></Icon>
                    </Badge>
                    <Icon type="ios-albums"  style="margin-left: 10px;" v-if="hasnewfile==false"></Icon>
                </template>
                <el-table :data="recoderfilesTrue"  border  empty-text="请在 历次记录 中 双击 选择查看">
                    <el-table-column  width="65" label="标识" :show-overflow-tooltip='true' align="center"> 
                        <template slot-scope="scope"> 
                            <img class="default-image" :src="$store.state.images.wujiaoxing" style="width：45px;height:45px;"> 
                        </template> 
                    </el-table-column>
                    <el-table-column type="index" width="80" label="序号"  :index="indexbf" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
                    <el-table-column prop="year" width="100" label="年份"   :show-overflow-tooltip='true' sortable align="center"></el-table-column>
                    <el-table-column prop="dwname" width="345" label="党委名称" :show-overflow-tooltip='true' sortable align="center" v-if="showName<=1"></el-table-column>
                    <el-table-column prop="dzbname" width="345" label="党支部名称" :show-overflow-tooltip='true' sortable align="center" v-if="showName==1"></el-table-column>
                    <el-table-column prop="uptime" width="125" label="上交时间" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
                    <el-table-column prop="name" width="125" label="捐款人姓名" :show-overflow-tooltip='true' sortable align="center" v-if="showName==2"></el-table-column>
                    <el-table-column prop="money" width="125" label="捐款金额" :show-overflow-tooltip='true' sortable align="center"></el-table-column>
                    <el-table-column align="right">
                        <template slot="header" slot-scope="scope">
                            <el-button  size="mini"    @click="serchfileJG">查询</el-button>
                            <el-button  size="mini"  @click="addfileJG" v-show="showAddF">新增</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination @size-change="SizeChangeB" @current-change="CurrentChangeB" :current-page.sync="currentPageB" :page-sizes="[10, 20, 50, 100]" :page-size="pageSizeB" layout="sizes,total, prev, pager, next" :total="totalB"></el-pagination>
            </el-collapse-item>
        </el-collapse>
        <bayrjadd ref='bayrjadd' v-on:editResult="serchfileJG"></bayrjadd>
    </div>
</template>
<script>
    import {mapActions} from 'vuex';
    export default {
        data: () => ({
            detailsVisible:false,
            activeNames:'1',
            disabledTwo:false,
            typeA:'',
            typeB:'',
            hasnewfile:false,
            Tabs:[],
            year:'',
            //第二个表格
            showAdd:false,
            showAddF:false,
            showName:0,
            filetype:'',//文件分类 默认from
            Filerecode:'',//当前的记录id
            recoderfiles:[], //获取到的文件
            recoderfilesTrue:[],//真正在表格里面显示的 由于分页等原因

            // 表格分页
            currentPageB:1,//当前页码
            pageSizeB:10, //当前表格中显示的数据的总个数
            totalB:0 //默认一页显示数量
        }),
        watch: {
            "detailsVisible": {
                handler(n) {
                    if(this.detailsVisible==true)
                    {
                        let _this=this;
                        //1 去后台获取当前dwid dzbid的在当前的tabs（）222
                        this.GetTabs(this.typeA+'-'+this.typeB)
                        .then(function(value){
                            _this.Tabs=value.Ltabs;
                        })
                        let showAddRecord=true;
                        if (this.$store.state.user.operation == 0 &&(this.$store.state.Dw_DzbID.dwid == -1 && this.$store.state.Dw_DzbID.dzbid == -1)) 
                        {
                            showAddRecord = true;
                        }
                        setTimeout(function () {
                            _this.$refs.lcjl.$data.typeA=_this.typeA;
                            _this.$refs.lcjl.$data.typeB=_this.typeB;
                            _this.$refs.lcjl.$data.showAdd=showAddRecord;
                            _this.$refs.lcjl.$data.samedwdzb=true;
                        }, 100)
                        if(this.$store.state.Dw_DzbID.dwid ==-1){
                            this.showName=0;
                        }
                        else if(this.$store.state.Dw_DzbID.dzbid ==-1){
                            this.showName=1;
                        }
                        else{
                            this.showName=2;
                        }
                        if (this.$store.state.user.operation <= 2 &&(this.$store.state.Dw_DzbID.dwid > -1 && this.$store.state.Dw_DzbID.dzbid > -1)) 
                        {
                            this.showAddF = true;
                        }
                    } 
                },
                deep: true
            }, 
            "filerecordes": {
                handler(n) {
                    if(this.filerecordes.length>0){
                    }
                    else
                    {
                        this. disabledTwo=false;
                    }
                },
                deep: true
            }, 

        },
        components: {
            bayrjadd: function(resolve) {require(["./bayrjadd.vue"], resolve);},
        },
        mounted() {
            this.$Common.Config.this = this;
            if (this.GetUser() == false) {
                this.$router.push("/");
            }
            
        },
        methods: {
            ...mapActions(['GetUser', 'GetTabs']),
            serchrecorde(data){
                this.filerecordes=data;
            },
            dbFilerecode(data,time){
                this.disabledTwo=true;
                this.year=new Date(time).getFullYear()
                this.activeNames='2';
                this.$refs.showfiles.$data.Filerecode=data;
                this.$refs.showfiles.$data.Tabs=this.Tabs;
                this.$refs.showfiles.$data.columns={
                    normal:
                    [
                        {
                            prop:'time',
                            width:'155',
                            label:'来文时间',
                        },
                        {
                            prop:'bianhao',
                            width:'155',
                            label:'文件编号',
                        },
                        {
                            prop:'name',
                            width:'155',
                            label:'文件名称',
                        },
                        {
                            prop:'jieguo',
                            width:'155',
                            label:'办理结果',
                        },
                        {
                            prop:'store',
                            width:'125',
                            label:'实际存放',
                        },
                    ],
                    showstatus:{
                        show:true,
                        prop:'status',
                        width:'125',
                        label:'办理状态',
                    },
                    showcontent:{
                        show:true,
                        prop:'content',
                        width:'125',
                        label:'内容查看',
                    },
                    showdownload:{
                        show:true,
                        prop:'truesrc',
                        width:'125',
                        label:'内容下载',
                    }
                }
            },
            //博爱一日捐的结果
            serchfileJG(){
                this.recoderfiles=[];this.showdataB();
                let _this=this;
                let postdata={
                    type:"serchbayrj",
                    split:JSON.stringify({
                        dwid:this.$store.state.Dw_DzbID.dwid,
                        dzbid:this.$store.state.Dw_DzbID.dzbid,
                        year:this.year
                    })
                }
                this.$Common.AjaxPost(postdata,true)
                .then(function(e){
                    if(e.bayrjs.length==0){
                        _this.$message({
                            message:'没有找到记录',
                            type:'info'
                        });
                    }
                    else{
                        _this.recoderfiles=e.bayrjs; 
                        _this.showdataB();
                    }
                }).catch(function(reason) {
                    console.log('catch:', reason);
                });
            },
            addfileJG(){
                this.$refs.bayrjadd.$data.dialogVisible = true;
                this.$refs.bayrjadd.$data.rowdata.year = this.year;
            },
            showdataB(){
                this.totalB=this.recoderfiles.length;
                if (this.recoderfiles.length >= 0)
                {
                    let offset = (this.currentPageB - 1) * this.pageSizeB;
                    this.recoderfilesTrue=this.recoderfiles.slice(offset, this.pageSizeB+offset);
                }
            },
            SizeChangeB(val){
                this.pageSizeB = val;
                this.showdataB();
            },
            CurrentChangeB(val){
                this.currentPageB = val;
                this.showdataB();
            },
            indexbf(index){
                let offset = (this.currentPageB - 1) * this.pageSizeB;
                return index+offset+1;
            },

        }
    }
</script>
<style>
</style>